package com.yanfan.accessControl.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.StringUtils;
import com.yanfan.ibms.common.vo.DeviceVo;
import com.yanfan.system.util.DeptTypeUtils;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanfan.accessControl.mapper.IbmsAccessControlDeviceMapper;
import com.yanfan.accessControl.domain.IbmsAccessControlDevice;
import com.yanfan.accessControl.service.IIbmsAccessControlDeviceService;

/**
 * 门禁系统设备Service业务层处理
 *
 * @author genluo
 * @date 2024-09-20
 */
@Service
public class IbmsAccessControlDeviceServiceImpl extends ServiceImpl<IbmsAccessControlDeviceMapper, IbmsAccessControlDevice> implements IIbmsAccessControlDeviceService {
    @Autowired
    private IbmsAccessControlDeviceMapper ibmsAccessControlDeviceMapper;

    @Autowired
    private DeptTypeUtils deptTypeUtils;

    /**
     * 查询门禁系统设备列表
     *
     * @param ibmsAccessControlDevice 门禁系统设备
     * @return 门禁系统设备
     */
    @Override
    public List<IbmsAccessControlDevice> queryPageList(IbmsAccessControlDevice ibmsAccessControlDevice) {
        LambdaQueryWrapper<IbmsAccessControlDevice> lqw = buildQueryWrapper(ibmsAccessControlDevice);
        return ibmsAccessControlDeviceMapper.selectList(lqw);
//        String deptType = deptTypeUtils.deptType();
//        if (deptType.equals("园区")){
//            deptType = null;
//        }else if(deptType.equals("商业")){
//            deptType = "商业";
//        }else if(deptType.equals("住宅")){
//            deptType = "住宅";
//        }
//        ibmsAccessControlDevice.setIsBusiness(deptType);
        //连表查询可用该方法，在此方法SQL语句上进行扩展
//        return ibmsAccessControlDeviceMapper.queryPageList(ibmsAccessControlDevice);
    }

    @Override
    public List<DeviceVo> selectByDeviceType(String deptType) {
        List<DeviceVo>list = ibmsAccessControlDeviceMapper.selectByDeviceType(deptType);
        List<DeviceVo> deviceTypeList = new ArrayList<>();
        for (DeviceVo deviceVo : list) {
            deviceVo.setDeviceType("门禁");
            deviceTypeList.add(deviceVo);
        }

        return deviceTypeList;
    }

    /**
     * 分页查询条件
     * @return
     */
    private LambdaQueryWrapper<IbmsAccessControlDevice> buildQueryWrapper(IbmsAccessControlDevice bo) {
        LambdaQueryWrapper<IbmsAccessControlDevice> lqw = Wrappers.lambdaQuery();
        //lqw.eq(bo.getDeviceSysId() != null, IbmsAccessControlDevice::getDeviceSysId, bo.getDeviceSysId());
        lqw.eq(bo.getPort() != null, IbmsAccessControlDevice::getPort, bo.getPort());
        lqw.eq(StringUtils.isNotBlank(bo.getSerial()), IbmsAccessControlDevice::getSerial, bo.getSerial());
        lqw.eq(StringUtils.isNotBlank(bo.getStationIp()), IbmsAccessControlDevice::getStationIp, bo.getStationIp());
        lqw.like(StringUtils.isNotBlank(bo.getStationName()), IbmsAccessControlDevice::getStationName, bo.getStationName());
        lqw.eq(StringUtils.isNotBlank(bo.getStationNo()), IbmsAccessControlDevice::getStationNo, bo.getStationNo());
        lqw.eq(StringUtils.isNotBlank(bo.getStationType()), IbmsAccessControlDevice::getStationType, bo.getStationType());
        lqw.eq(StringUtils.isNotBlank(bo.getIsBusiness()), IbmsAccessControlDevice::getIsBusiness, bo.getIsBusiness());
        return lqw;
    }



}
